﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MinecraftEnchantCalculator.Data.Entity;
using MinecraftEnchantCalculator.Enums;

namespace MinecraftEnchantCalculator.ViewModels.Windows.MainWindowComponents;

public partial class EnchantViewModel : ViewModelBase
{
  [ObservableProperty] private bool _isEnabled = true;

  [ObservableProperty] private bool _isSelected;
  [ObservableProperty] private int _level;

  public EnchantViewModel(Enchantment enchantment, SpellType spell)
  {
    Enchantment = enchantment with { Level = enchantment.MaxLevel };
    Spell = spell;
    Level = enchantment.MaxLevel;
  }
  
  public Enchantment Enchantment { get; private set; }
  public SpellType Spell { get; }

  [RelayCommand]
  private void Increasing()
  {
    if (Level < Enchantment.MaxLevel) ++Level;
  }

  [RelayCommand]
  private void Decreasing()
  {
    if (Level > 1) --Level;
  }

  partial void OnLevelChanged(int value)
  {
    Enchantment = Enchantment with { Level = value };
  }
}